
/** 
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.tompai.common.time;

import java.text.ParseException;
import java.time.Clock;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

/**
* @desc: datagather-tools
* @name: Test.java
* @author: tompai
* @createTime: 2018年4月28日 下午11:01:22
* @history:
* @version: v1.0
*/

public class LocalTimeTest {

	/**
	* @author: tompai
	* @createTime: 2018年4月28日 下午11:01:22
	* @history:
	* @param args void
	*/

	public static void main(String[] args) {
		//TODO Auto-generated method stub

		String tmpTime="2018/04/23 13:00:00";
		tmpTime=tmpTime.replaceAll("/", "-");
		System.out.println("tmpTime "+tmpTime);  
		//String formatType="yyyy-MM-dd HH:mm:ss";
		String formatType="yyyy-MM-dd HH:mm:ss";
		Date date=new Date();
		//System.out.println("date1:"+date.toString());
		
		Instant instant = Instant.now();
		//System.out.println("date1:"+date.toString());
		Clock clock = Clock.systemDefaultZone();// 获取系统默认时区 (当前瞬时时间 )  
		  
        // Get the local date/time  
        final LocalDateTime datetime = LocalDateTime.now();  
        final LocalDateTime datetimeFromClock = LocalDateTime.now(clock);  
        
        
       // System.out.println(datetime);  
        //System.out.println(datetimeFromClock);  
	    // 因为中国在东八区，所以这句输出的时间跟我的电脑时间是不同的
	    //System.out.println("date2:"+clock.millis());
	    
		//long currentTime=System.currentTimeMillis();
        long currentTime =1525191474200L;
        //                1525226065616
		try {
			System.out.print("date3:"+TimeTransUtils.stringToDate("tmpTime", formatType));
			//System.out.print("date4:"+TimeTransUtils.longToDate(currentTime, formatType));
		} catch (ParseException e) {
			
			//TODO Auto-generated catch block
			e.printStackTrace();
			
		}
		
		Clock clock2 = Clock.systemDefaultZone();// 获取系统默认时区 (当前瞬时时间 )  
		// Get the zoned date/time  
		final ZonedDateTime zonedDatetime = ZonedDateTime.now();  
		final ZonedDateTime zonedDatetimeFromClock = ZonedDateTime.now(clock2);  
		final ZonedDateTime zonedDatetimeFromZone = ZonedDateTime.now(ZoneId.of("America/Los_Angeles"));  
		System.out.println(zonedDatetime);  
		System.out.println(zonedDatetimeFromClock);  
		System.out.println(zonedDatetimeFromZone);  
	}

}

